/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package OLDSTUFF.ClassAlgebra;

/**
 *
 * @author Martin Haulrich
 */
public class SimpleProbExpr implements ProbExpr {

    public final Expression e;

    final int hash;


    public SimpleProbExpr(Expression e) {
        this.e = e;
        hash = e.hashCode();
    }


    @Override
    public String toString() {
        String es = e.toString();
        if (e.type() == Expression.SIMPLE || e.type() == Expression.EMPTY || e.type() == Expression.LIST) {
            es = "(" + es + ")";
        }
        return "F*" + es;
    }


    @Override
    public Object clone() throws CloneNotSupportedException {
        /**
         * @TODO The API dictates that by convention this method should be implemented useing super.clone(). Consider changing the code to do this.
         */
        return new SimpleProbExpr(e);
    }


    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final SimpleProbExpr other = (SimpleProbExpr) obj;
        if (hash != other.hash) {
            return false;
        }
        if (this.e != other.e && (this.e == null || !this.e.equals(other.e))) {
            return false;
        }
        return true;
    }


//    @Override
//    public boolean equals(Object o) {
//
//        if (o instanceof SimpleProbExpr) {
//            if (o.hashCode() != hash) {
//                return false;
//            }
//            SimpleProbExpr pe = (SimpleProbExpr) o;
//            //        System.err.println("SimProb: " + e + " : " + pe.e + "   " + e.equals(pe));
//            return (e.equals(pe.e));
//        }
//        return false;
//    }


    @Override
    public int hashCode() {

        return hash;
    }
}
